﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Configuration;
using System.Collections;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.IO;

namespace ConfigurationToolForBizTalk
{
    public partial class ConfigManager : Form
    {
        public ConfigManager()
        {
            InitializeComponent();
            hostConfig.SelectedIndexChanged += new EventHandler(Tabs_SelectedIndexChanged);
            tabControl1.SelectedIndexChanged += new EventHandler(ResumeTabs_SelectedIndexChanged);
            tabControl2.SelectedIndexChanged += new EventHandler(TerminateTabs_SelectedIndexChanged);
        }

        #region CommonFunctions
        private void ConfigManager_Load(object sender, EventArgs e)
        {
            #region HostInstance
            hostList.Items.Clear();
            restartHost.Items.Clear();
            int i = 0;
            EnumerationOptions enumOptions = new EnumerationOptions();
            enumOptions.ReturnImmediately = false;
            ManagementObjectSearcher searchObject = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_HostInstance where HostType=1", enumOptions);
            int nNumHostInstFound = searchObject.Get().Count;
            string[] values = new string[nNumHostInstFound];
            foreach (ManagementObject inst in searchObject.Get())
            {
                values[i] = inst["HostName"].ToString();
                i++;
            }
            hostList.Items.AddRange(values);
            restartHost.Items.AddRange(values);

            /* Code for Showing Already Ignored Host Instances */
            IgnoreListFromConfig.Items.Clear();
            int j = 0;
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            string HostValues = config.AppSettings.Settings["Ignorable_HostInstance"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            ////ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();               
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            IgnoreListFromConfig.Items.AddRange(stringList.ToArray());
            #endregion
            #region SendPorts
            sndPortList.Items.Clear();
            int snd = 0;
            EnumerationOptions enumOptionsSnd = new EnumerationOptions();
            enumOptionsSnd.ReturnImmediately = false;
            ManagementObjectSearcher searchObjectSnd = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_SendPort", enumOptionsSnd);
            int nNumSndInstFound = searchObjectSnd.Get().Count;
            string[] valuesSnd = new string[nNumSndInstFound];
            foreach (ManagementObject inst in searchObjectSnd.Get())
            {
                valuesSnd[snd] = inst["Name"].ToString();
                snd++;
            }
            sndPortList.Items.AddRange(valuesSnd);
            IgnoredSndPort.Items.Clear();
            int SndIgn = 0;
            string appPathSnd = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFileSnd = System.IO.Path.Combine(appPathSnd, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMapSnd = new ExeConfigurationFileMap();
            configFileMapSnd.ExeConfigFilename = configFileSnd;
            Configuration configSnd = ConfigurationManager.OpenMappedExeConfiguration(configFileMapSnd, ConfigurationUserLevel.None);
            configSnd.Save(ConfigurationSaveMode.Modified);
            string SndValues = configSnd.AppSettings.Settings["Ignorable_SendPorts"].Value;
            string[] ListSndValues = SndValues.Split(',');
            string[] SndignoredList = new string[ListSndValues.Length];
            foreach (string data in ListSndValues)
            {
                if (data.Length > 0)
                {
                    SndignoredList[SndIgn] = data;
                    SndIgn++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringListsnd = new List<string>();
            foreach (string data in SndignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringListsnd.Add(data);
                }
            }
            IgnoredSndPort.Items.AddRange(stringListsnd.ToArray());
            #endregion
            #region ReceiveLocations
            rcvLocList.Items.Clear();
            int rcv = 0;
            EnumerationOptions enumOptionsRcv = new EnumerationOptions();
            enumOptionsRcv.ReturnImmediately = false;
            ManagementObjectSearcher searchObjectRcv = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_ReceiveLocation", enumOptionsRcv);
            int nNumRcvLocFound = searchObjectRcv.Get().Count;
            string[] valuesRcv = new string[nNumRcvLocFound];
            foreach (ManagementObject inst in searchObjectRcv.Get())
            {
                valuesRcv[rcv] = inst["Name"].ToString();
                rcv++;
            }
            rcvLocList.Items.AddRange(valuesRcv);

            AlreadyIgnoredRcvLoc.Items.Clear();
            int rcvIgn = 0;
            string appPathRcv = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFileRcv = System.IO.Path.Combine(appPathRcv, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMapRcv = new ExeConfigurationFileMap();
            configFileMapRcv.ExeConfigFilename = configFileRcv;
            Configuration configRcv = ConfigurationManager.OpenMappedExeConfiguration(configFileMapRcv, ConfigurationUserLevel.None);
            string RcvValues = configRcv.AppSettings.Settings["Ignorable_ReceiveLocations"].Value;
            string[] ListRcvValues = HostValues.Split(',');
            string[] ignoredRcvList = new string[ListRcvValues.Length];
            foreach (string data in ListRcvValues)
            {
                if (data.Length > 0)
                {
                    ignoredRcvList[rcvIgn] = data;
                    rcvIgn++;
                }
            }
            ////ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringRcvList = new List<string>();
            foreach (string data in ignoredRcvList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringRcvList.Add(data);
                }
            }
            AlreadyIgnoredRcvLoc.Items.AddRange(stringRcvList.ToArray());
            #endregion
            #region ResumeOrchTab
            orchNameList.Items.Clear();
            int orcRes = 0;
            EnumerationOptions enumOptionsOrcRes = new EnumerationOptions();
            enumOptionsOrcRes.ReturnImmediately = false;
            ManagementObjectSearcher searchObjectOrcRes = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_Orchestration", enumOptionsOrcRes);
            int nNumOrcResInstFound = searchObjectOrcRes.Get().Count;
            string[] valuesOrcRes = new string[nNumOrcResInstFound];
            string[] Assemblyvalues = new string[nNumOrcResInstFound];
            foreach (ManagementObject inst in searchObjectOrcRes.Get())
            {
                valuesOrcRes[orcRes] = inst["Name"].ToString();
                Assemblyvalues[orcRes] = inst["AssemblyName"].ToString();
                valuesOrcRes[orcRes] = valuesOrcRes[orcRes].Replace(Assemblyvalues[orcRes], "");
                valuesOrcRes[orcRes] = valuesOrcRes[orcRes].Replace(".", "");
                orcRes++;
            }
            orchNameList.Items.AddRange(valuesOrcRes);

            AlreadyAddedOrchName.Items.Clear();
            int orcResIgn = 0;
            string appPathorcResIgn = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFileorcResIgn = System.IO.Path.Combine(appPathorcResIgn, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMaporcResIgn = new ExeConfigurationFileMap();
            configFileMaporcResIgn.ExeConfigFilename = configFileorcResIgn;
            Configuration configorcResIgn = ConfigurationManager.OpenMappedExeConfiguration(configFileMaporcResIgn, ConfigurationUserLevel.None);
            string orcResIgnValues = configorcResIgn.AppSettings.Settings["ResumableMessages_OrchestrationName"].Value;
            string[] ListorcResIgnValues = orcResIgnValues.Split(',');
            string[] ignoredorcResIgnList = new string[ListorcResIgnValues.Length];
            foreach (string data in ListorcResIgnValues)
            {
                if (data.Length > 0)
                {
                    ignoredorcResIgnList[orcResIgn] = data;
                    orcResIgn++;
                }
            }
            ////ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringListorcResIgn = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringListorcResIgn.Add(data);
                }
            }
            AlreadyAddedOrchName.Items.AddRange(stringListorcResIgn.ToArray());
            #endregion
            #region TermOrcTab
            listOrchTerminate.Items.Clear();
            int TermOrc = 0;
            EnumerationOptions enumOptionsTermOrc = new EnumerationOptions();
            enumOptionsTermOrc.ReturnImmediately = false;
            ManagementObjectSearcher searchObjectTermOrc = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_Orchestration", enumOptionsTermOrc);
            int nNumTermOrcInstFound = searchObjectTermOrc.Get().Count;
            string[] valuesTermOrc = new string[nNumTermOrcInstFound];
            string[] AssemblyvaluesTermOrc = new string[nNumTermOrcInstFound];
            foreach (ManagementObject inst in searchObjectTermOrc.Get())
            {
                valuesTermOrc[TermOrc] = inst["Name"].ToString();
                AssemblyvaluesTermOrc[TermOrc] = inst["AssemblyName"].ToString();
                valuesTermOrc[TermOrc] = valuesTermOrc[TermOrc].Replace(AssemblyvaluesTermOrc[TermOrc], "");
                valuesTermOrc[TermOrc] = valuesTermOrc[TermOrc].Replace(".", "");
                TermOrc++;
            }
            listOrchTerminate.Items.AddRange(valuesTermOrc);

            AlreadyTerminateOrch.Items.Clear();
            int TermOrcIgn = 0;
            string appPathTermOrcIgn = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFileTermOrcIgn = System.IO.Path.Combine(appPathTermOrcIgn, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMapTermOrcIgn = new ExeConfigurationFileMap();
            configFileMapTermOrcIgn.ExeConfigFilename = configFileTermOrcIgn;
            Configuration configTermOrcIgn = ConfigurationManager.OpenMappedExeConfiguration(configFileMapTermOrcIgn, ConfigurationUserLevel.None);
            string TermOrcIgnValues = configTermOrcIgn.AppSettings.Settings["TerminateMessages_OrchestrationName"].Value;
            string[] ListTermOrcIgnValues = TermOrcIgnValues.Split(',');
            string[] ignoredTermOrcIgnList = new string[ListTermOrcIgnValues.Length];
            foreach (string data in ListTermOrcIgnValues)
            {
                if (data.Length > 0)
                {
                    ignoredTermOrcIgnList[TermOrcIgn] = data;
                    TermOrcIgn++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringTermOrcIgnList = new List<string>();
            foreach (string data in ignoredTermOrcIgnList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringTermOrcIgnList.Add(data);
                }
            }
            AlreadyTerminateOrch.Items.AddRange(stringTermOrcIgnList.ToArray());
            #endregion
            #region Orchestrations
            orchList.Items.Clear();
            List<string> stringOrchList = new List<string>();
            foreach (string data in orchNameList.Items)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringOrchList.Add(data);
                }
            }
            orchList.Items.AddRange(stringOrchList.ToArray());

            IgnoredOrchList.Items.Clear();
            int orcIgn = 0;
            string appPathorcIgn = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFileorcIgn = System.IO.Path.Combine(appPathorcIgn, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMaporcIgn = new ExeConfigurationFileMap();
            configFileMaporcIgn.ExeConfigFilename = configFileorcIgn;
            Configuration configorcIgn = ConfigurationManager.OpenMappedExeConfiguration(configFileMaporcIgn, ConfigurationUserLevel.None);
            string orcIgnValues = configorcIgn.AppSettings.Settings["Ignorable_Orchestrations"].Value;
            string[] ListorcIgnValues = orcIgnValues.Split(',');
            string[] ignoredorcIgnList = new string[ListorcIgnValues.Length];
            foreach (string data in ListorcIgnValues)
            {
                if (data.Length > 0)
                {
                    ignoredorcIgnList[orcIgn] = data;
                    orcIgn++;
                }
            }
            ////ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringListorcIgn = new List<string>();
            foreach (string data in ignoredorcIgnList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringListorcIgn.Add(data);
                }
            }
            IgnoredOrchList.Items.AddRange(stringListorcIgn.ToArray());
            #endregion
        }
        private void MoveListBoxItems(ListBox source, ListBox destination)
        {
            ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
            foreach (var item in sourceItems)
            {
                destination.Items.Add(item);
            }
        }
        private void Tabs_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region EmailPage
            if (hostConfig.SelectedTab == tabPage13)
            {
                string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
                string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFile;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
                if (config.AppSettings.Settings["SMTPServer"].Value.Length > 0)
                {
                    string server = config.AppSettings.Settings["SMTPServer"].Value;
                    smtp.Text = server;
                }
                if (config.AppSettings.Settings["PortNumber"].Value.Length > 0)
                {
                    string portnum = config.AppSettings.Settings["PortNumber"].Value;
                    port.Text = portnum;
                }
                if (config.AppSettings.Settings["FromAddress"].Value.Length > 0)
                {
                    string frmAdd = config.AppSettings.Settings["FromAddress"].Value;
                    frm.Text = frmAdd;
                }
                if (config.AppSettings.Settings["PassWord"].Value.Length > 0)
                {
                    string passwrd = config.AppSettings.Settings["PassWord"].Value;
                    password.Text = passwrd;
                }
                if (config.AppSettings.Settings["ToAddress"].Value.Length > 0)
                {
                    string toAdd = config.AppSettings.Settings["ToAddress"].Value;
                    to.Text = toAdd;
                }
                if (config.AppSettings.Settings["CCAddress"].Value.Length > 0)
                {
                    string ccAdd = config.AppSettings.Settings["CCAddress"].Value;
                    cc.Text = ccAdd;
                }
                if (config.AppSettings.Settings["Subject"].Value.Length > 0)
                {
                    string subject = config.AppSettings.Settings["Subject"].Value;
                    subj.Text = subject;
                }
                if (config.AppSettings.Settings["FullReport"].Value.Length > 0)
                {
                    string fullrprt = config.AppSettings.Settings["FullReport"].Value;
                    fullreport.Text = fullrprt;
                }

            }
            #endregion
        }
        private void ResumeTabs_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region ThroughSendPortName
            listOfPorts.Items.Clear();
            if (tabControl1.SelectedTab == tabPage7)
            {
                List<string> stringPortList = new List<string>();
                foreach (string data in sndPortList.Items)
                {
                    if (!(String.IsNullOrEmpty(data)))
                    {
                        stringPortList.Add(data);
                    }
                }
                listOfPorts.Items.AddRange(stringPortList.ToArray());
                AlreadyAddedURL.Items.Clear();
                int k = 0;
                string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
                string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFile;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
                string HostValues = config.AppSettings.Settings["ResumableMessages_SendPort"].Value;
                string[] ListHostValues = HostValues.Split(',');
                string[] ignoredList = new string[ListHostValues.Length];
                foreach (string data in ListHostValues)
                {
                    if (data.Length > 0)
                    {
                        ignoredList[k] = data;
                        k++;
                    }
                }
                //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
                List<string> stringList = new List<string>();
                foreach (string data in ignoredList)
                {
                    if (!(String.IsNullOrEmpty(data)))
                    {
                        stringList.Add(data);
                    }
                }
                AlreadyAddedURL.Items.AddRange(stringList.ToArray());
            }
            #endregion
            #region ThroughErrorDescription
            if (tabControl1.SelectedTab == tabPage8)
            {
                AlreadySavedErrDes.Items.Clear();
                int k = 0;
                string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
                string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFile;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
                string HostValues = config.AppSettings.Settings["ResumableMessages_ErrorDescription"].Value;
                string[] ListHostValues = HostValues.Split(',');
                string[] ignoredList = new string[ListHostValues.Length];
                foreach (string data in ListHostValues)
                {
                    if (data.Length > 0)
                    {
                        ignoredList[k] = data;
                        k++;
                    }
                }
                //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
                List<string> stringList = new List<string>();
                foreach (string data in ignoredList)
                {
                    if (!(String.IsNullOrEmpty(data)))
                    {
                        stringList.Add(data);
                    }
                }
                AlreadySavedErrDes.Items.AddRange(stringList.ToArray());
            }
            #endregion
        }
        private void TerminateTabs_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region ThroughSendPortName
            if (tabControl2.SelectedTab == tabPage11)
            {
                list_sndPortName.Items.Clear();
                List<string> stringPortList = new List<string>();
                foreach (string data in sndPortList.Items)
                {
                    if (!(String.IsNullOrEmpty(data)))
                    {
                        stringPortList.Add(data);
                    }
                }
                list_sndPortName.Items.AddRange(stringPortList.ToArray());
                ListedSndPorts.Items.Clear();
                int k = 0;
                string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
                string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFile;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
                string HostValues = config.AppSettings.Settings["TerminateMessages_SendPort"].Value;
                string[] ListHostValues = HostValues.Split(',');
                string[] ignoredList = new string[ListHostValues.Length];
                foreach (string data in ListHostValues)
                {
                    if (data.Length > 0)
                    {
                        ignoredList[k] = data;
                        k++;
                    }
                }
                //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
                List<string> stringList = new List<string>();
                foreach (string data in ignoredList)
                {
                    if (!(String.IsNullOrEmpty(data)))
                    {
                        stringList.Add(data);
                    }
                }
                ListedSndPorts.Items.AddRange(stringList.ToArray());
            }
            #endregion
            #region ThroughErrorDescription
            if (tabControl2.SelectedTab == tabPage12)
            {
                listofErrDes.Items.Clear();
                int k = 0;
                string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
                string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFile;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
                string HostValues = config.AppSettings.Settings["TerminateMessages_ErrorDescription"].Value;
                string[] ListHostValues = HostValues.Split(',');
                string[] ignoredList = new string[ListHostValues.Length];
                foreach (string data in ListHostValues)
                {
                    if (data.Length > 0)
                    {
                        ignoredList[k] = data;
                        k++;
                    }
                }
                //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
                List<string> stringList = new List<string>();
                foreach (string data in ignoredList)
                {
                    if (!(String.IsNullOrEmpty(data)))
                    {
                        stringList.Add(data);
                    }
                }
                listofErrDes.Items.AddRange(stringList.ToArray());
            }
            #endregion
        }
        public static void SendFailureReport()
        {
            try
            {
                string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
                string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFile;
                Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
                string server = config.AppSettings.Settings["SMTPServer"].Value;
                string portnum = config.AppSettings.Settings["PortNumber"].Value;
                string frmAdd = config.AppSettings.Settings["FromAddress"].Value;
                string toAdd = config.AppSettings.Settings["ToAddress"].Value;
                string ccAdd = config.AppSettings.Settings["CCAddress"].Value;
                string subject = config.AppSettings.Settings["Subject"].Value;
                string passwrd = config.AppSettings.Settings["PassWord"].Value;
                SmtpClient client = new SmtpClient(server);
                MailMessage Msg = new MailMessage();
                if (portnum.Length > 0)
                {
                    client.Port = Int32.Parse(portnum);
                }
                string[] listfrmAdd = frmAdd.Split(',');
                foreach (string frm in listfrmAdd)
                {
                    if (frm.Length > 0)
                    {
                        Msg.From = new MailAddress(frm);
                    }
                }
                string[] listToAdd = toAdd.Split(',');
                foreach (string to in listToAdd)
                {
                    if (to.Length > 0)
                    {
                        Msg.To.Add(to);
                    }
                }
                string[] listCCAdd = ccAdd.Split(',');
                foreach (string cc in listCCAdd)
                {
                    if (cc.Length > 0)
                    {
                        Msg.CC.Add(cc);
                    }
                }
                Msg.Subject = subject;
                Msg.Body = "Test Mail";
                if (passwrd.Length > 0)
                {
                    client.Credentials = new System.Net.NetworkCredential(frmAdd, passwrd);
                }
                else
                {
                    client.UseDefaultCredentials = true;
                }
                client.Send(Msg);
                Console.WriteLine("Mail Sent Succesfully");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Mail Sending Failed" + ex.Message);
                Console.ReadLine(); //To be removed Code for Release version
            }
        }
        #endregion
        #region HostInstancePageSpecific
        private void hostList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void label2_Click(object sender, EventArgs e)
        {

        }
        private void MoveRight_Click(object sender, EventArgs e)
        {
            if (hostList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to move");
            }
            MoveListBoxItems(hostList, IgnoreListFromConfig);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_HostInstance");
            foreach (string item in IgnoreListFromConfig.Items)
            {
                app.Settings.Add("Ignorable_HostInstance", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
        }
        private void button3_Click(object sender, EventArgs e)
        {

        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void pageReLoad_Click(object sender, EventArgs e)
        {

        }
        private void MoveLeft_Click(object sender, EventArgs e)
        {
            if (IgnoreListFromConfig.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to Remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_HostInstance"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in IgnoreListFromConfig.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_HostInstance");
            app.Settings.Add("Ignorable_HostInstance", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in IgnoreListFromConfig.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                IgnoreListFromConfig.Items.Remove(remove);
            }
        }
        private void refreshHostpage_Click(object sender, EventArgs e)
        {
            IgnoreListFromConfig.Items.Clear();
            ConfigManager_Load(sender, e);
        }
        private void button3_Click_1(object sender, EventArgs e)
        {
            for (int i = 0; i < hostList.Items.Count; i++)
            {
                hostList.SetSelected(i, true);
            }
            MoveListBoxItems(hostList, IgnoreListFromConfig);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_HostInstance");
            foreach (string item in IgnoreListFromConfig.Items)
            {
                app.Settings.Add("Ignorable_HostInstance", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
            for (int i = 0; i < hostList.Items.Count; i++)
            {
                hostList.SetSelected(i, false);
            }
        }
        private void button10_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < IgnoreListFromConfig.Items.Count; i++)
            {
                IgnoreListFromConfig.SetSelected(i, true);
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_HostInstance"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in IgnoreListFromConfig.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_HostInstance");
            app.Settings.Add("Ignorable_HostInstance", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in IgnoreListFromConfig.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                IgnoreListFromConfig.Items.Remove(remove);
            }
        }
        private void restartHost_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void allHostStart_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < restartHost.Items.Count; i++)
            {
                restartHost.SetSelected(i, true);
            }
            try
            {
                //Create EnumerationOptions and run wql query
                EnumerationOptions enumOptions = new EnumerationOptions();
                enumOptions.ReturnImmediately = false;
                //Search for all HostInstances of 'InProcess' type in the Biztalk namespace scope
                ManagementObjectSearcher searchObject = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_HostInstance where HostType=1", enumOptions);

                //Enumerate through the result set and start each HostInstance if it is already stopped
                foreach (ManagementObject inst in searchObject.Get())
                {
                    if (inst["ServiceState"].ToString() == "1")
                    {
                        inst.InvokeMethod("Start", null);
                    }
                    else
                    {
                        inst.InvokeMethod("Stop", null);
                        inst.InvokeMethod("Start", null);
                    }
                }
                restartHost.ClearSelected();
            }
            catch (Exception excep)
            {
                Console.WriteLine("Failure while starting HostInstances - " + excep.Message);
                Console.ReadLine();
            }
        }
        private void selHostStart_Click(object sender, EventArgs e)
        {
            if (restartHost.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please Select Host Instance To Re-Start");
            }
            try
            {
                //Create EnumerationOptions and run wql query
                EnumerationOptions enumOptions = new EnumerationOptions();
                enumOptions.ReturnImmediately = false;
                //Search for all HostInstances of 'InProcess' type in the Biztalk namespace scope
                ManagementObjectSearcher searchObject = new ManagementObjectSearcher(ConfigurationManager.AppSettings["BizTalkServer"].ToString(), "Select * from MSBTS_HostInstance where HostType=1", enumOptions);

                //Enumerate through the result set and start each HostInstance if it is already stopped
                foreach (ManagementObject inst in searchObject.Get())
                {
                    foreach (string value in restartHost.SelectedItems)
                    {
                        if ((inst["HostName"].ToString() == value))
                        {
                            if (inst["ServiceState"].ToString() == "1")
                            {
                                inst.InvokeMethod("Start", null);
                            }
                            else
                            {
                                inst.InvokeMethod("Stop", null);
                                inst.InvokeMethod("Start", null);
                            }
                        }
                    }
                }
                restartHost.ClearSelected();
            }
            catch (Exception excep)
            {
                Console.WriteLine("Failure while starting HostInstances - " + excep.Message);
                Console.ReadLine();
            }
        }
        #endregion
        #region SendPortsSpecific
        private void label6_Click(object sender, EventArgs e)
        {

        }
        private void label5_Click(object sender, EventArgs e)
        {

        }
        private void IgnoredSndPort_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void sndPortList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void MoveToIgnoreSndPort_Click(object sender, EventArgs e)
        {
            if (sndPortList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to Move");
            }
            MoveListBoxItems(sndPortList, IgnoredSndPort);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_SendPorts");
            foreach (string item in IgnoredSndPort.Items)
            {
                app.Settings.Add("Ignorable_SendPorts", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
        }
        private void button2_Click(object sender, EventArgs e)
        {
        }
        private void removeIgnoredSndPort_Click(object sender, EventArgs e)
        {
            if (IgnoredSndPort.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_SendPorts"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in IgnoredSndPort.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_SendPorts");
            app.Settings.Add("Ignorable_SendPorts", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in IgnoredSndPort.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                IgnoredSndPort.Items.Remove(remove);
            }
        }
        private void refreshSndPortPage_Click(object sender, EventArgs e)
        {
            IgnoredSndPort.Items.Clear();
            ConfigManager_Load(sender, e);
        }
        private void sndPort_AllIgnore_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < sndPortList.Items.Count; i++)
            {
                sndPortList.SetSelected(i, true);
            }
            MoveListBoxItems(sndPortList, IgnoredSndPort);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_SendPorts");
            foreach (string item in IgnoredSndPort.Items)
            {
                app.Settings.Add("Ignorable_SendPorts", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
            for (int i = 0; i < sndPortList.Items.Count; i++)
            {
                sndPortList.SetSelected(i, false);
            }
        }
        private void sndPort_AllConsider_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < IgnoredSndPort.Items.Count; i++)
            {
                IgnoredSndPort.SetSelected(i, true);
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_SendPorts"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in IgnoredSndPort.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_SendPorts");
            app.Settings.Add("Ignorable_SendPorts", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in IgnoredSndPort.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                IgnoredSndPort.Items.Remove(remove);
            }
        }
        #endregion
        #region ReceiveLocationsSpecific
        private void rcvLocList_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void RcvLocToIgnoreList_Click(object sender, EventArgs e)
        {
            if (rcvLocList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to Move");
            }
            MoveListBoxItems(rcvLocList, AlreadyIgnoredRcvLoc);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_ReceiveLocations");
            foreach (string item in AlreadyIgnoredRcvLoc.Items)
            {
                app.Settings.Add("Ignorable_ReceiveLocations", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
        }
        private void SaveRcvLoc_Click(object sender, EventArgs e)
        {
        }
        private void AlreadyIgnoredRcvLoc_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void RefreshRcvLocPage_Click(object sender, EventArgs e)
        {
            AlreadyIgnoredRcvLoc.Items.Clear();
            ConfigManager_Load(sender, e);
        }
        private void RemoveRcvLocFromConfig_Click(object sender, EventArgs e)
        {
            if (AlreadyIgnoredRcvLoc.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_ReceiveLocations"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in AlreadyIgnoredRcvLoc.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_ReceiveLocations");
            app.Settings.Add("Ignorable_ReceiveLocations", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in AlreadyIgnoredRcvLoc.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                AlreadyIgnoredRcvLoc.Items.Remove(remove);
            }
        }
        private void RcvLoc_AllIgnore_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < rcvLocList.Items.Count; i++)
            {
                rcvLocList.SetSelected(i, true);
            }
            MoveListBoxItems(rcvLocList, AlreadyIgnoredRcvLoc);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_ReceiveLocations");
            foreach (string item in AlreadyIgnoredRcvLoc.Items)
            {
                app.Settings.Add("Ignorable_ReceiveLocations", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
            for (int i = 0; i < rcvLocList.Items.Count; i++)
            {
                rcvLocList.SetSelected(i, false);
            }
        }
        private void RcvLoc_AllConsider_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < AlreadyIgnoredRcvLoc.Items.Count; i++)
            {
                AlreadyIgnoredRcvLoc.SetSelected(i, true);
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_ReceiveLocations"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in AlreadyIgnoredRcvLoc.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_ReceiveLocations");
            app.Settings.Add("Ignorable_ReceiveLocations", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in AlreadyIgnoredRcvLoc.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                AlreadyIgnoredRcvLoc.Items.Remove(remove);
            }
        }
        #endregion
        #region ResumingSuspendedInstances
        #region ThroughOrchestrationName
        private void orchNameList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (orchNameList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items in the box");
            }
            MoveListBoxItems(orchNameList, ToBeAddedOrch);
        }
        private void saveOrchName_Click(object sender, EventArgs e)
        {
            if (ToBeAddedOrch.SelectedItems.Count == 0 && String.IsNullOrEmpty(OrchNametxtbox.Text))
            {
                MessageBox.Show("Please add items to save");
            }
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            if (!(ToBeAddedOrch.SelectedItems.Count == 0))
            {
                foreach (string item in ToBeAddedOrch.Items)
                {
                    app.Settings.Add("ResumableMessages_OrchestrationName", item);
                }
            }
            if (!(String.IsNullOrEmpty(OrchNametxtbox.Text)))
            {
                app.Settings.Add("ResumableMessages_OrchestrationName", OrchNametxtbox.Text);
            }
            config.Save(ConfigurationSaveMode.Modified);

            AlreadyAddedOrchName.Items.Clear();
            int j = 0;
            string HostValues = config.AppSettings.Settings["ResumableMessages_OrchestrationName"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            AlreadyAddedOrchName.Items.AddRange(stringList.ToArray());
        }
        private void button4_Click(object sender, EventArgs e)
        {
            OrchNametxtbox.Clear();
            ToBeAddedOrch.Items.Clear();
            ConfigManager_Load(sender, e);
        }
        private void removeOrchName_Click(object sender, EventArgs e)
        {
            if (AlreadyAddedOrchName.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["ResumableMessages_OrchestrationName"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in AlreadyAddedOrchName.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("ResumableMessages_OrchestrationName");
            app.Settings.Add("ResumableMessages_OrchestrationName", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in AlreadyAddedOrchName.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                AlreadyAddedOrchName.Items.Remove(remove);
            }
        }
        private void orchNameTip_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Please Note that the Orchestration Name to be entered would be only the service name."
                            + Environment.NewLine +
                            "For Example :-"
                            + Environment.NewLine +
                            "If the Name value of Orchestration is 'Microsoft.BizTalk.Edi.RoutingOrchestration.BatchRoutingService'"
                            + Environment.NewLine +
                            "If the Assembly value of Orchestration is 'Microsoft.BizTalk.Edi.RoutingOrchestration, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"
                            + Environment.NewLine +
                            "Then Your ServiceName for Orchestration is Name Value - Assembly Value i.e. 'BatchRoutingService'");
        }
        #endregion
        #region ThroughSendPortName
        private void listOfPorts_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void ToBeAddedOrchURL_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            if (listOfPorts.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items in the box");
            }
            MoveListBoxItems(listOfPorts, ToBeAddedOrchURL);
        }
        private void saveURL_Click(object sender, EventArgs e)
        {
            if (ToBeAddedOrchURL.SelectedItems.Count == 0 && String.IsNullOrEmpty(sndPortName.Text))
            {
                MessageBox.Show("Please add items to save");
            }
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            if (!(ToBeAddedOrchURL.SelectedItems.Count == 0))
            {
                foreach (string item in ToBeAddedOrchURL.Items)
                {
                    app.Settings.Add("ResumableMessages_SendPort", item);
                }
            }
            if (!(String.IsNullOrEmpty(sndPortName.Text)))
            {
                app.Settings.Add("ResumableMessages_SendPort", sndPortName.Text);
            }
            config.Save(ConfigurationSaveMode.Modified);

            AlreadyAddedURL.Items.Clear();
            int j = 0;
            string HostValues = config.AppSettings.Settings["ResumableMessages_SendPort"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            AlreadyAddedURL.Items.AddRange(stringList.ToArray());
        }
        private void refreshOrchURL_Click(object sender, EventArgs e)
        {
            ToBeAddedOrchURL.Items.Clear();
            ResumeTabs_SelectedIndexChanged(sender, e);
        }
        private void button7_Click(object sender, EventArgs e)
        {
            if (AlreadyAddedURL.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["ResumableMessages_SendPort"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in AlreadyAddedURL.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("ResumableMessages_SendPort");
            app.Settings.Add("ResumableMessages_SendPort", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in AlreadyAddedURL.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                AlreadyAddedURL.Items.Remove(remove);
            }
        }
        #endregion
        #region ThroughErrDesc
        private void saveErrDesc_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(errDescInput.Text))
            {
                MessageBox.Show("Please Input the Error Description");
            }
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            if (!(String.IsNullOrEmpty(errDescInput.Text)))
            {
                app.Settings.Add("ResumableMessages_ErrorDescription", errDescInput.Text);
            }
            config.Save(ConfigurationSaveMode.Modified);

            AlreadySavedErrDes.Items.Clear();
            int j = 0;
            string HostValues = config.AppSettings.Settings["ResumableMessages_ErrorDescription"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            AlreadySavedErrDes.Items.AddRange(stringList.ToArray());
        }
        private void refreshErrDes_Click(object sender, EventArgs e)
        {
            errDescInput.Clear();
            ConfigManager_Load(sender, e);
        }
        private void removeErrDesc_Click(object sender, EventArgs e)
        {
            if (AlreadySavedErrDes.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["ResumableMessages_ErrorDescription"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in AlreadySavedErrDes.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("ResumableMessages_ErrorDescription");
            app.Settings.Add("ResumableMessages_ErrorDescription", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in AlreadySavedErrDes.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                AlreadySavedErrDes.Items.Remove(remove);
            }
        }
        #endregion
        #endregion
        #region TerminatingSuspendedInstances
        #region ThroughOrchestrationName
        private void listOrchTerminate_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void Move_TerOrch_Click(object sender, EventArgs e)
        {
            MoveListBoxItems(listOrchTerminate, ToBeTerminateOrch);
        }
        private void save_TerOrch_Click(object sender, EventArgs e)
        {
            if (ToBeTerminateOrch.SelectedItems.Count == 0 && String.IsNullOrEmpty(textBox_OrchNameToTerminate.Text))
            {
                MessageBox.Show("Please add items to save");
            }
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            if (!(ToBeTerminateOrch.SelectedItems.Count == 0))
            {
                foreach (string item in ToBeTerminateOrch.Items)
                {
                    app.Settings.Add("TerminateMessages_OrchestrationName", item);
                }
            }
            if (!(String.IsNullOrEmpty(textBox_OrchNameToTerminate.Text)))
            {
                app.Settings.Add("TerminateMessages_OrchestrationName", textBox_OrchNameToTerminate.Text);
            }
            config.Save(ConfigurationSaveMode.Modified);

            AlreadyTerminateOrch.Items.Clear();
            int j = 0;
            string HostValues = config.AppSettings.Settings["TerminateMessages_OrchestrationName"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            AlreadyTerminateOrch.Items.AddRange(stringList.ToArray());
        }
        private void refresh_terorch_Click(object sender, EventArgs e)
        {
            textBox_OrchNameToTerminate.Clear();
            ToBeTerminateOrch.Items.Clear();
            ConfigManager_Load(sender, e);
        }
        private void remove_terOrch_Click(object sender, EventArgs e)
        {
            if (AlreadyTerminateOrch.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["TerminateMessages_OrchestrationName"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in AlreadyTerminateOrch.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("TerminateMessages_OrchestrationName");
            app.Settings.Add("TerminateMessages_OrchestrationName", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in AlreadyTerminateOrch.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                AlreadyTerminateOrch.Items.Remove(remove);
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Please Note that the Orchestration Name to be entered would be only the service name."
                            + Environment.NewLine +
                            "For Example :-"
                            + Environment.NewLine +
                            "If the Name value of Orchestration is 'Microsoft.BizTalk.Edi.RoutingOrchestration.BatchRoutingService'"
                            + Environment.NewLine +
                            "If the Assembly value of Orchestration is 'Microsoft.BizTalk.Edi.RoutingOrchestration, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"
                            + Environment.NewLine +
                            "Then Your ServiceName for Orchestration is Name Value - Assembly Value i.e. 'BatchRoutingService'");
        }
        #endregion
        #region ThroughSendPortName
        private void list_sndPortName_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private void button14_Click(object sender, EventArgs e)
        {
            MoveListBoxItems(list_sndPortName, TobeAdded_SndTerm);
        }
        private void button13_Click(object sender, EventArgs e)
        {
            if (TobeAdded_SndTerm.SelectedItems.Count == 0 && String.IsNullOrEmpty(sndPortTextbox.Text))
            {
                MessageBox.Show("Please add items to save");
            }
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            if (!(TobeAdded_SndTerm.SelectedItems.Count == 0))
            {
                foreach (string item in TobeAdded_SndTerm.Items)
                {
                    app.Settings.Add("TerminateMessages_SendPort", item);
                }
            }
            if (!(String.IsNullOrEmpty(sndPortTextbox.Text)))
            {
                app.Settings.Add("TerminateMessages_SendPort", sndPortTextbox.Text);
            }
            config.Save(ConfigurationSaveMode.Modified);

            ListedSndPorts.Items.Clear();
            int j = 0;
            string HostValues = config.AppSettings.Settings["TerminateMessages_SendPort"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            ListedSndPorts.Items.AddRange(stringList.ToArray());
        }
        private void button12_Click(object sender, EventArgs e)
        {
            sndPortTextbox.Clear();
            TobeAdded_SndTerm.Items.Clear();
            TerminateTabs_SelectedIndexChanged(sender, e);
        }
        private void button11_Click(object sender, EventArgs e)
        {
            if (ListedSndPorts.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["TerminateMessages_SendPort"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in ListedSndPorts.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("TerminateMessages_SendPort");
            app.Settings.Add("TerminateMessages_SendPort", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in ListedSndPorts.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                ListedSndPorts.Items.Remove(remove);
            }
        }
        #endregion
        #region ThroughErrDesc
        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
        private void button17_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox3.Text))
            {
                MessageBox.Show("Please Input the Error Description");
            }
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            if (!(String.IsNullOrEmpty(textBox3.Text)))
            {
                app.Settings.Add("TerminateMessages_ErrorDescription", textBox3.Text);
            }
            config.Save(ConfigurationSaveMode.Modified);

            listofErrDes.Items.Clear();
            int j = 0;
            string HostValues = config.AppSettings.Settings["TerminateMessages_ErrorDescription"].Value;
            string[] ListHostValues = HostValues.Split(',');
            string[] ignoredList = new string[ListHostValues.Length];
            foreach (string data in ListHostValues)
            {
                if (data.Length > 0)
                {
                    ignoredList[j] = data;
                    j++;
                }
            }
            //ignoredList = ignoredList.Where(s => !String.IsNullOrEmpty(s)).ToArray();
            List<string> stringList = new List<string>();
            foreach (string data in ignoredList)
            {
                if (!(String.IsNullOrEmpty(data)))
                {
                    stringList.Add(data);
                }
            }
            listofErrDes.Items.AddRange(stringList.ToArray());
        }
        private void button15_Click(object sender, EventArgs e)
        {
            textBox3.Clear();
            TerminateTabs_SelectedIndexChanged(sender, e);
        }
        private void button16_Click(object sender, EventArgs e)
        {
            if (listofErrDes.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["TerminateMessages_ErrorDescription"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in listofErrDes.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("TerminateMessages_ErrorDescription");
            app.Settings.Add("TerminateMessages_ErrorDescription", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in listofErrDes.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                listofErrDes.Items.Remove(remove);
            }
        }
        #endregion
        #endregion
        #region Orchestrations
        private void AddSelectedOrch_Click(object sender, EventArgs e)
        {
            if (orchList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to Move");
            }
            MoveListBoxItems(orchList, IgnoredOrchList);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_Orchestrations");
            foreach (string item in IgnoredOrchList.Items)
            {
                app.Settings.Add("Ignorable_Orchestrations", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
        }
        private void AddAllOrch_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < orchList.Items.Count; i++)
            {
                orchList.SetSelected(i, true);
            }
            MoveListBoxItems(orchList, IgnoredOrchList);
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings.Remove("Ignorable_Orchestrations");
            foreach (string item in IgnoredOrchList.Items)
            {
                app.Settings.Add("Ignorable_Orchestrations", item);
            }
            config.Save(ConfigurationSaveMode.Modified);
            for (int i = 0; i < orchList.Items.Count; i++)
            {
                orchList.SetSelected(i, false);
            }
        }
        private void RemoveAllOrch_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < IgnoredOrchList.Items.Count; i++)
            {
                IgnoredOrchList.SetSelected(i, true);
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_Orchestrations"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in IgnoredOrchList.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_Orchestrations");
            app.Settings.Add("Ignorable_Orchestrations", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in IgnoredOrchList.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                IgnoredOrchList.Items.Remove(remove);
            }
        }
        private void RemoveSelectedOrch_Click(object sender, EventArgs e)
        {
            if (IgnoredOrchList.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select items to remove");
            }
            ArrayList removeKey = new ArrayList();
            ArrayList refreshListbox = new ArrayList();
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string HostValues = config.AppSettings.Settings["Ignorable_Orchestrations"].Value;
            ArrayList ListHostValues = new ArrayList();
            ListHostValues.AddRange(HostValues.Split(','));
            foreach (string item in ListHostValues)
            {
                foreach (object myitems in IgnoredOrchList.SelectedItems)
                {
                    if (item == "" || item == null)
                    {
                        removeKey.Add(item);
                    }
                    if (item == myitems.ToString())
                    {
                        removeKey.Add(item);
                    }
                }
            }
            foreach (var item in removeKey)
            {
                ListHostValues.Remove(item);
            }
            string keyValue = string.Join(",", Array.ConvertAll<object, string>(ListHostValues.ToArray(), Convert.ToString));
            app.Settings.Remove("Ignorable_Orchestrations");
            app.Settings.Add("Ignorable_Orchestrations", keyValue);
            config.Save(ConfigurationSaveMode.Modified);
            foreach (object item in IgnoredOrchList.SelectedItems)
            {
                refreshListbox.Add(item);
            }
            foreach (object remove in refreshListbox)
            {
                IgnoredOrchList.Items.Remove(remove);
            }
        }
        private void refreshOrchPage_Click(object sender, EventArgs e)
        {
            ConfigManager_Load(sender, e);
        }
        #endregion
        #region EmailSettings
        private void button8_Click(object sender, EventArgs e)
        {
            string appPath = ConfigurationManager.AppSettings["ToolConfigPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, ConfigurationManager.AppSettings["ConfigFileName"].ToString());
            ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            string server = config.AppSettings.Settings["SMTPServer"].Value;
            string portnum = config.AppSettings.Settings["PortNumber"].Value;
            string frmAdd = config.AppSettings.Settings["FromAddress"].Value;
            string toAdd = config.AppSettings.Settings["ToAddress"].Value;
            string ccAdd = config.AppSettings.Settings["CCAddress"].Value;
            string subject = config.AppSettings.Settings["Subject"].Value;
            app.Settings.Remove("SMTPServer");
            app.Settings.Remove("PortNumber");
            app.Settings.Remove("FromAddress");
            app.Settings.Remove("PassWord");
            app.Settings.Remove("ToAddress");
            app.Settings.Remove("CCAddress");
            app.Settings.Remove("Subject");
            app.Settings.Remove("FullReport");
            app.Settings.Add("SMTPServer", smtp.Text);
            app.Settings.Add("PortNumber", port.Text);
            app.Settings.Add("FromAddress", frm.Text);
            app.Settings.Add("PassWord", password.Text);
            app.Settings.Add("ToAddress", to.Text);
            app.Settings.Add("CCAddress", cc.Text);
            app.Settings.Add("Subject", subj.Text);
            app.Settings.Add("FullReport", fullreport.Text);
            config.Save(ConfigurationSaveMode.Modified);
            label46.Visible = true;
            MessageBox.Show("Please Click On \"Send Test E-Mail\" To Verify SMTP Settings");
        }
        private void button6_Click(object sender, EventArgs e)
        {
            SendFailureReport();
            label45.Visible = true;
        }
        private void button9_Click(object sender, EventArgs e)
        {
            label46.Visible = false;
            label45.Visible = false;
            Tabs_SelectedIndexChanged(sender, e);
        }
        private void label51_Click(object sender, EventArgs e)
        {

        }
        #endregion
    }
}

